<template>
  <base-layout>
    <template #searchPanel>
      <search-panel
        @search="search"
        @insert="addStore"
        :showAddButton="true"
        :addPer="authConfig.add"
        :selectPer="authConfig.query"
      >
        <CitySelect v-model="form.cityCode" />
        <el-select
          clearable
          v-model="form.status"
          placeholder="店面状态"
        >
          <el-option
            v-for="item in dict['门店状态']"
            :key="item.index"
            :value="item.value"
            :label="item.text"
          />
        </el-select>
        <el-input
          v-model="form.storeName"
          clearable
          placeholder="店面名称"
          style="width: 200px"
        />
        <el-input
          v-model="form.managerName"
          clearable
          placeholder="店长名称"
          style="width: 200px"
        />
      </search-panel>
    </template>
    <template #contentPanel>
      <data-table
        :value="tableData"
        :total-count="totalCount"
        :has-action="true"
        :table-column-attributes="tableColumnAttributes"
        @row-dblclick="showRote"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :width="160"
      >
        <template #action="{ row }">
          <i
            class="el-icon-edit"
            title="修改"
            style="margin-left: 20px; cursor: pointer"
            v-permission="authConfig.edit"
            @click="updateRow(row, '修改门店信息')"
          ></i>
          <i
            class="el-icon-delete"
            title="删除"
            style="color: red; margin-left: 20px; cursor: pointer"
            v-permission="authConfig.del"
            @click="delRow(row)"
          ></i>
        </template>
      </data-table>
      <!--工具条-->
    </template>
  </base-layout>
</template>

<script>
import {
  dataList,
  dicts,
  details,
  addData,
  updateData,
  deleteData,
} from "@/api/after-sale/systemManage/store";
import baseMixin from "@/mixins/base";
import { parseTimeToYMDHMS } from "@/utils";
import { getDict } from "@/utils/index";
import store from '@/store/index';
export default {
  mixins: [
    baseMixin({
      idName: "id",
      findData: dataList,
      dataName: ["content", "totalRecords"],
      addData: addData,
      updateData: updateData,
      deleteData: deleteData,
      isAdd: false,
      findDataById: details,
      idName: "id",
      format (res) {
        return res.map((data) => {
          data.businessHours = `${data.startTime}-${data.endTime}`;
          data.status = data.status ? "营业" : "停业";
          return data;
        });
      },
    }),
  ],
  data () {
    return {
      authConfig: {
        query: 'store:page',
        add: 'store:create',
        edit: 'store:update',
        del: 'store:delete',
      },
      dialogVisible: false,
      isAdd: false,
      tableColumnAttributes: [
        { name: "店面名称", value: "storeName", type: "text", width: "200" },
        { name: "所属城市", value: "city", type: "text", width: "100" },
        { name: "所属区域", value: "county", type: "text", width: "100" },
        { name: "详细地址", value: "address", type: "text", width: "200" },
        { name: "在职人数", value: "activeStaff", type: "text", width: "100" },
        { name: "主营业务", value: "note", type: "text", width: "200" },
        { name: "店长", value: "managerName", type: "text", width: "100" },
        {
          name: "联系电话",
          value: "managerPhone",
          type: "text",
          width: "100",
        },
        {
          name: "层级",
          value: "storeLevelName",
          type: "text",
          width: "100",
        },
        {
          name: "营业时间",
          value: "businessHours",
          type: "text",
          width: "100",
        },
        { name: "店面状态", value: "status", type: "text", width: "100" },
        { name: "创建时间", value: "createTime", type: "text", width: "150" },
      ],
      dict: {},

      form: {
        cityCode: "", //城市编码
        managerName: "", //店长名称
        status: "", //门店状态
        storeId: "", //门店id
        storeName: "", //门店名称
      },
    };
  },
  async created () {
    this.dict = getDict(["门店状态"]);
  },
  methods: {
    async delRow (row) {
      this.handleDataDelete(row);
      await store.dispatch('getUserInfo')
    },
    //查看
    showRote (row) {
      row.id &&
        this.$router.push({
          path: "/systemManage/showStore",
          query: {
            status: "show",
            id: row.id,
          },
        });
    },
    updateRow (row) {
      row.id &&
        this.$router.push({
          path: "/systemManage/updataStore",
          query: {
            status: "edit",
            id: row.id,
          },
        });
    },
    search () {
      this.searchOptions = this.form;
      this.currentPage = 1;
      this.setTableData();
    },
    //新增
    addStore () {
      this.$router.push({
        path: "/systemManage/addStore",
      });
    },
    handleChange () {
      this.form.provinceId = "";
      this.form.cityId = "";
      this.form.county = "";
    },
  },
};
</script>

<style lang="scss" scoped></style>
